/**
 * Copyright 2007 American Well Systems
 * All rights reserved.
 *
 * It is illegal to use, reproduce or distribute
 * any part of this Intellectual Property without
 * prior written authorization from American Well.
 */
package org.ddevil.data.util;

/**
 * Timing is everything.
 * @author Rich O'Connell
 */
public class StopWatch {
	long start;
	long lastDiff;

	/**
	 * Constructor, stop watch will start running now.
	 */
	public StopWatch() {
		start();
	}

	/**
	 * Start running the stop watch.
	 */
	public void start() {
		start = System.currentTimeMillis();
	}

	/**
	 * Return the current running time in seconds.
	 * @return
	 */
	public String read() {
		long diff = System.currentTimeMillis() - start;
		return seconds(diff);
	}

	/**
	 * Return the current running time, in seconds and restart the clock.
	 * @return
	 */
	public String readReset() {
		String rt = read();
		start();
		return rt;
	}


	private static String seconds(long ms) {
		return Long.toString(ms/1000L) + " sec.";
	}

}
